package com.xfp.controller;


import com.xfp.pojo.dto.VmTypePageDto;
import com.xfp.pojo.dto.newVmTypeDto;
import com.xfp.pojo.vo.VmTypePageVo;
import com.xfp.pojo.vo.VmTypeVo;
import com.xfp.result.Result;
import com.xfp.service.VmTypeSrevice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/vmType")
@Slf4j
@Api(tags="设备接口")
public class VmTypeController {

    @Autowired
    private VmTypeSrevice vmTypeSrevice;

    /**
     * 分页查询设备类型
     * @param
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("售货机分页查询")
    public VmTypePageVo queryVmType(VmTypePageDto dto){
        log.info("售货机分页查询：{}",dto);
        VmTypePageVo vo = vmTypeSrevice.queryVmType(dto);
        return vo;
    }

    /**
     * 新增设备类型
     */
    @PostMapping
    @ApiOperation("新增设备类型")
    public Boolean insetVmType(@RequestBody newVmTypeDto dto){
        log.info("新增设备类型");
        vmTypeSrevice.insertVmType(dto);
        return true;
    }

    /**
     * 修改设备类型
     */
    @PutMapping("/{typeId}")
    @ApiOperation("修改设备类型")
    public Boolean updateVmType(@PathVariable Long typeId,@RequestBody newVmTypeDto dto){
        log.info("修改设备类型");
        vmTypeSrevice.updateVmType(typeId,dto);
        return true;
    }

    /**
     * 删除设备类型
     */
    @DeleteMapping("/{typeId}")
    @ApiOperation("删除设备类型")
    public Result<Boolean> deleteType(@PathVariable Long typeId){
        log.info("删除设备类型：{}",typeId);
        vmTypeSrevice.deleteType(typeId);
        return Result.success(true);
    }

    /**
     *
     */
    @GetMapping("/{typeId}")
    @ApiOperation("售货机类型详情")
    public VmTypeVo findType(@PathVariable Integer typeId){
        log.info("售货机类型详情");
        VmTypeVo vo = vmTypeSrevice.findType(typeId);
        return vo;
    }

}
